{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Miscellaneous\n", "\n", "1. [Feedback](#Feedback)\n", "2. [Transforms](#Transforms)\n", " 1. [Fourier Transform](#Fourier-Transform)\n", " 2. [Laplace Transform](#Laplace-Transform)\n", " 3. [$z$-Transform](#$z$-Transform)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Feedback" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import rwth_nb.misc.feedback as rwth_feedback\n", "\n", "mail_to = \"example@rwth-aachen.de\" # send feedback via mail\n", "feedback_name = rwth_feedback.get_notebook_name() # get name of notebook automatically\n", "rwth_feedback.rwth_feedback(feedback_name, [\n", " {'id': 'likes', 'type': 'free-text', 'label': 'Das war gut:'}, \n", " {'id': 'dislikes', 'type': 'free-text', 'label': 'Das könnte verbessert werden:'}, \n", " {'id': 'misc', 'type': 'free-text', 'label': 'Was ich sonst noch sagen möchte:'}, \n", " {'id': 'learning', 'type': 'scale', 'label' : 'Ich habe das Gefühl etwas gelernt zu haben.'},\n", " {'id': 'supervision', 'type': 'scale', 'label' : 'Die Betreuung des Versuchs war gut.'},\n", " {'id': 'script', 'type': 'scale', 'label' : 'Die Versuchsunterlagen sind verständlich.'},\n", "], \"feedback.json\", mail_to)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Transforms\n", "\n", "Following transforms are defined in `rwth_nb.misc.transforms`:\n", "\n", "- [Fourier Transform](#Fourier-Transform)\n", "- [Laplace Transform](#Laplace-Transform)\n", "- [$z$-Transform](#$z$-Transform)\n", "\n", "*Note that plotting basics are described in [RWTH Plots](RWTH%20Plots.ipynb).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Fourier Transform\n", "\n", "```dft(s, fs, NFFT)```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "import rwth_nb.plots.mpl_decorations as rwth_plots\n", "import rwth_nb.misc.transforms as rwth_transforms\n", "\n", "\n", "# Time Domain\n", "fs = 44100 # very high sampling rate assumed, to simulate quasi-continuous time and frequency axis\n", "t = np.linspace(-2.5, 2.5, 5*fs)\n", "s = np.sin(2*np.pi*500*t)\n", "\n", "# Fourier Transform\n", "S,f = rwth_transforms.dft(s, fs)\n", "\n", "# plots\n", "fig,axs = plt.subplots(2,1, **rwth_plots.landscape);\n", "\n", "ax = axs[0]; ax.plot(t*1000, s);\n", "ax.set_xlabel(r'$\\rightarrow t$ [ms]'); ax.set_ylabel(r'$\\uparrow s(t)$')\n", "ax.set_xlim([-11, 11]); ax.set_ylim([-1.1, 1.19]); rwth_plots.axis(ax);\n", "\n", "ax = axs[1]; ax.plot(f, np.abs(S));\n", "ax.set_xlabel(r'$\\rightarrow f$ [Hz]'); ax.set_ylabel(r'$\\uparrow |S(f)|$')\n", "ax.set_xlim([-1100, 1100]); ax.set_ylim([0, 0.65]); rwth_plots.axis(ax);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Inverse Fourier transform\n", "\n", "```idft(S, Ntime, NFF)```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s2 = rwth_transforms.idft(S, len(s));\n", "\n", "fig,ax = plt.subplots(**rwth_plots.landscape); \n", "ax.plot(t*1000, np.real(s2));\n", "ax.set_xlabel(r'$\\rightarrow t$ [ms]'); ax.set_ylabel(r'$\\uparrow \\mathcal{F}^{-1}\\{S(f)\\}$')\n", "ax.set_xlim([-11, 11]); ax.set_ylim([-1.1, 1.19]); rwth_plots.axis(ax);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Laplace Transform\n", "Pole-zero plot is explained in [RWTH Plots](RWTH%20Plots.ipynb). \n", "\n", "Inverse Laplace Transform\n", "\n", "```ilaplace_ht(t, H0, pp, pz, ord_p, ord_z, roc)```\n", "\n", "```ilaplace_Hf(f, H0, pp, pz, ord_p, ord_z, dB)```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig,axs = plt.subplots(1, 2, figsize=(10, 4))\n", "\n", "t = np.linspace(-6, 6, 1024)\n", "f = np.linspace(-6, 6, 1024)\n", "\n", "pp = np.array([-2]); pz = np.array([]) # Poles and Zeros\n", "ord_p = np.array([1]); ord_z = np.array([]) # Poles' and Zeros' orders\n", "roc = np.array([-2, np.inf]) # region of convergence\n", "H0 = 1\n", "\n", "# Time Domain\n", "s1, t1d , s1d = rwth_transforms.ilaplace_ht(t, H0, pp, pz, ord_p, ord_z, roc)\n", "\n", "ax = axs[0]\n", "ax.set_xlabel(r'$\\rightarrow t$'); ax.set_ylabel(r'$\\uparrow s_1(t)$') \n", "rwth_plots.grid(ax); rwth_plots.axis(ax)\n", "ax.set_xlim([-5.5,5.5]); axs[0].set_ylim([-0.1,1.05]); \n", "ax.plot(t, np.real(s1))\n", "rwth_plots.plot_dirac(axs[0], t1d, s1d);\n", "\n", "# Frequency Domain\n", "S1f = rwth_transforms.ilaplace_Hf(f, H0, pp, pz, ord_p, ord_z, dB=False)\n", "\n", "ax = axs[1]\n", "ax.set_xlabel(r'$\\rightarrow f$'); ax.set_ylabel(r'$\\uparrow S_1(f)$') \n", "rwth_plots.grid(ax); rwth_plots.axis(ax)\n", "ax.set_xlim([-5.5,5.5]); ax.set_ylim([-0.1,0.55]); \n", "ax.plot(f, S1f); " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### $z$ Transform\n", "Pole-zero plot is explained in [RWTH Plots](RWTH%20Plots.ipynb). \n", "\n", "Inverse $z$ Transform\n", "\n", "```iz_hn(n, H0, pp, pz, ord_p, ord_z, roc)```\n", "\n", "```iz_Hf(f, H0, pp, pz, ord_p, ord_z, dB)```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig,axs = plt.subplots(1, 2, figsize=(10, 4))\n", "\n", "n = np.linspace(-6, 6, 13)\n", "f = np.linspace(-6, 6, 1024)\n", "\n", "zp = np.array([.5, 2]); zz = np.array([0]) # Poles and Zeros\n", "ord_p = np.array([1, 1]); ord_z = np.array([1]) # Poles' and Zeros' orders\n", "roc = np.array([.5, 2]) # region of convergence\n", "H0 = -3/2\n", "\n", "# Time Domain\n", "s1= rwth_transforms.iz_hn(n, H0, zp, zz, ord_p, ord_z, roc)\n", "\n", "ax = axs[0]\n", "ax.set_xlabel(r'$\\rightarrow n$'); ax.set_ylabel(r'$\\uparrow s_1(n)$') \n", "rwth_plots.grid(ax); rwth_plots.axis(ax)\n", "ax.set_xlim([-5.5,5.5]); axs[0].set_ylim([-0.1,1.05]);\n", "rwth_plots.stem(axs[0], n, s1);\n", "\n", "# Frequency Domain\n", "S1f = rwth_transforms.iz_Hf(f, H0, zp, zz, ord_p, ord_z, dB=False)\n", "\n", "ax = axs[1]\n", "ax.set_xlabel(r'$\\rightarrow f$'); ax.set_ylabel(r'$\\uparrow S_1(f)$') \n", "rwth_plots.grid(ax); rwth_plots.axis(ax)\n", "ax.set_xlim([-5.5,5.5]); ax.set_ylim([0.3, 3.1]); \n", "ax.plot(f, S1f); " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This code is licensed under the [MIT license](https://opensource.org/licenses/MIT)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }